#!/usr/bin/env bash

set -e

source $SRCROOT/integration/common

trap exit_handler EXIT

heading 'Setup...'

echo 'logging in..'
# we do this at run-time instead of build time
# to eliminate the risk of copying over a stale chainlink binary
# if we had instead copied over the binary from the built chainlink
# base image
# we could also try mounting a volume instead, or using docker-exec
echo 'copy binary'
docker cp chainlink-node:/usr/local/bin/chainlink /usr/local/bin/chainlink
  waitForResponse $CHAINLINK_URL
  title "Chainlink is running."
echo 'chainlink admin login'
chainlink admin login --file /run/secrets/apicredentials
echo 'launch_chainlink'
launch_chainlink
echo 'deploy_contracts'
deploy_contracts

heading 'Running tests...'
cd $SRCROOT/integration

./runlog_test
./ethlog_test
deploy_v05_contracts

title 'End to end tests.'

yarn workspace @chainlink/integration test:cypress
title 'All tests passed.'
